﻿@using BabyShop.WebSite.Models
@model ProductType

@{
    ViewBag.Title = Model.ProductTypeGuid == Guid.Empty ? "Create ProductType" : "Edit ProductType";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

@using (Ajax.BeginForm("Create", null, new AjaxOptions { HttpMethod = "post", OnSuccess = "CreateSucc",
    OnFailure = "CreateFailure" }, new { id = "CreateForm" })) {
    @Html.ValidationSummary(true)
    <fieldset class="FormFieldset">
        <legend>@ViewBag.Title</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.ProductTypeName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.ProductTypeName)
            @Html.ValidationMessageFor(model => model.ProductTypeName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.ParentGuid)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(m => m.ParentGuid, ViewBag.ProductTypeList as SelectListItem[], "--无上级类型--")
            @Html.ValidationMessageFor(model => model.ParentGuid)
        </div>
        <div class="editor-label">
            @Html.LabelFor(m=>m.MenuType)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(m => m.MenuTypeInt, typeof(MenuType))
            @Html.ValidationMessageFor(model => model.MenuType)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.MenuUrl)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.MenuUrl)
            @Html.ValidationMessageFor(model => model.MenuUrl)
        </div>
    </fieldset>
    <div style="text-align: right;">
        <p>
            @Html.ActionLink("返回", "Index", null, new { id = "btnBack" })
            <input id="btnSubmit" type="submit" value="保存" />
        </p>
    </div>
    @Html.HiddenFor(m => m.ProductTypeGuid)
}

@section HeaderScript{
<script type="text/javascript">
    function CreateSucc(data, status) {
        if (status == 'success') {
            if (data.ErrorCode != 0)
                alert(data.ShowMsg);
            else {
                $.bs.showMsg('提示', data.ShowMsg);
                parent.window.frames[$.removePrefix($.sysRes.iframeName)].$('#btnSearch').click();
                $.bs.closeDialog();
            }
        }
    }

    function CreateFailure() {
        alert("Create failure.");
    }

    $(function () {
        $('#btnSubmit').button();
        $("#btnBack").button().click(function() {
            $.bs.closeDialog();
            return false;
        });
    });
</script>
}